#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
const int N=2e5;
#define INF 0x7fffffff
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//

void solve()
{
	string s1;
	cin>>s1;
	//all
	int a=(s1[0]-'a');//row
	int b=s1[1]-'a';//num in row
	if(b>a)
	{
		pd(a*26+b-(s1[0]-'a'));puts("");//每一列掉一部分
	}
	else
	{
		pd(a*26+b-(s1[0]-'a')+1);puts("");
	}
}

int main()
{
	int T;
	sd(T);
	while (T--)
	{
		solve();
	}
	return 0;
}